package spring.cloud.tasks.executor.name_space.executor.task.task_listener;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.tasks.executor.name_space.executor.task.TaskExecutor;
import spring.cloud.tasks.executor.name_space.executor.task.task_item.task_item_execute_info.TaskItemExecuteInfoNeedReportListenerHolder;
import spring.cloud.tasks.executor.name_space.executor.task.task_listener.task_configuration.TaskConfigurationListenerHolder;
import spring.cloud.tasks.executor.name_space.executor.task.task_listener.task_statistics.TaskResetStatisticsListenerHolder;
import spring.cloud.tasks.executor.name_space.executor.task.task_listener.trigger_task_execute.TriggerTaskExecuteListenerHolder;

/**
 * 任务注册中心的监听器管理者.
 */
@Slf4j
@Setter
@Getter
public class TaskListenerHolderManager extends TaskListenerHolder {
    private TaskConfigurationListenerHolder taskConfigurationListenerHolder;

    private TaskItemExecuteInfoNeedReportListenerHolder taskItemExecuteInfoNeedReportListenerHolder;
    private TriggerTaskExecuteListenerHolder triggerTaskExecuteListenerHolder;
    private TaskResetStatisticsListenerHolder taskResetStatisticsListenerHolder;

    public TaskListenerHolderManager(final TaskExecutor taskScheduler) {
        super(taskScheduler);
    }

    /**
     * 开启所有监听器.
     */
    @Override
    public void start() {
        taskConfigurationListenerHolder = new TaskConfigurationListenerHolder(taskExecutor);

        taskItemExecuteInfoNeedReportListenerHolder = new TaskItemExecuteInfoNeedReportListenerHolder(taskExecutor);
        triggerTaskExecuteListenerHolder = new TriggerTaskExecuteListenerHolder(taskExecutor);
        taskResetStatisticsListenerHolder = new TaskResetStatisticsListenerHolder(taskExecutor);
        //
        taskConfigurationListenerHolder.start();

        taskItemExecuteInfoNeedReportListenerHolder.start();
        triggerTaskExecuteListenerHolder.start();
        taskResetStatisticsListenerHolder.start();

    }

    @Override
    public void stop() {
        taskConfigurationListenerHolder.stop();

        taskItemExecuteInfoNeedReportListenerHolder.stop();
        triggerTaskExecuteListenerHolder.stop();
        taskResetStatisticsListenerHolder.stop();
    }
}
